package user.action;

import groupby.manage.GroupCriticismManage;
import groupby.manage.GroupbyManage;
import groupby.model.Category;
import groupby.model.GroupCriticism;
import groupby.util.Pages;
import groupby.util.UtilsTools;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import net.sf.json.JSONObject;

import org.apache.struts2.ServletActionContext;

import user.manage.UsersManage;
import user.model.BrandInfor;
import user.model.Photoinfor;
import user.model.Pictures;
import user.model.Topic;
import user.model.UserDetial;
import user.model.Users;

import com.opensymphony.xwork2.ActionSupport;

import dic.manage.DicManage;

public class BrandUserAction extends ActionSupport {
	private UsersManage userManage = null;
	private DicManage dicManage = null;
	private String photoName = null;
	private String description = null;
	private JSONObject result = null;
	private Pages pages = null;
	private List picturesList = null;
	private int currentPage;
	private int currentPages;
	private UserDetial userDetial = null;
	private int rows;
	private int picId;
	private int able;
	private String flag = null;
	private List groupbyCriticismList = null;
	private GroupCriticismManage groupCriticismManage = null;
	private GroupbyManage groupbyManage=null;
	private File[] upload;
	private String[] uploadContentType;
	private String[] uploadFileName;
	private String[] title;
	private String[] descriptions;
	
	private File imgFile;
	private String imgFileContentType;
	private String imgFileFileName;
	
    private List showPhotoList=null;
    private int photoId;
    private Photoinfor photoinfor;
    private String content; 
    private List criticismList;
    private Pages pagesCriticism;
    private String brandName;
    private int category;
    private  List brandInforList=null;
    private int userId;
    private Category singleCategory=null;
    private int brandId;
    private BrandInfor singleBrand=null;
    private List topicList=null;
    private int topicId;
    private Topic topic=null;
    private List otherTopicList=null;
    private List brandUserList=null;
    private int count;
    private List listDredgeCitys=null;
    private int page;
    private String startDate=null;
    private String endDate=null;
    private int category2;
    private Users users=null;
    private String url=null;
    private int publisher;
    private Pictures pic=null;
    private UserDetial publishers=null;
	@Override
	public String execute() throws Exception {

		return super.execute();
	}

	/**
	 * 添加相册
	 * 
	 * @return
	 * @throws Exception
	 */
	public String addPictures() throws Exception {

		Users users = (Users) ServletActionContext.getRequest().getSession()
				.getAttribute("user");
		if (users == null) {
			this.addActionError("你没有登录，请登录！");
			return "input";
		} else {
			Date date = new Date();
			Pictures picture = new Pictures();
			picture.setPhotoName(UtilsTools.convertToChinese(photoName));
			picture.setDescription(UtilsTools.convertToChinese(description));
			picture.setUserId(users.getId());
			String imageFolder = date.getTime() + "";
			String path = ServletActionContext.getRequest().getRealPath("/uploadFile")
					+ "\\" + imageFolder;
			path=path.replace("/", File.separator).replace("\\",File.separator);
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			File file = new File(path);
			
			picture.setDatetime(sdf.format(date));
			picture.setRecommend(0);
			picture.setFace("img.gif");
			picture.setCategoryId(category);
			boolean isSuccess = file.mkdirs();
			if (isSuccess) {
				picture.setImageFolder(imageFolder);
				boolean isAddSuccess = userManage.addPictures(picture);
				if (!isAddSuccess) {
					file.delete();
					this.addActionError("创建相册失败！");
					return "createError";
				}
			} else {
				this.addActionError("创建相册失败！");
				return "createError";
			}
		}
		photoName=null;
		return "success";
	}
	/**
	 * 置顶
	 * @return
	 */
    public String  topBrand()
    {
    		result=userManage.top(brandId,flag);
    		return "success";
    }
	/**
	 * 获得相册列表
	 * 
	 * @return
	 */
	public String pictureList() throws Exception {

		Users users = (Users) ServletActionContext.getRequest().getSession()
				.getAttribute("user");
		if (users == null) {
			this.addActionError("你没有登录，请登录！");
			return "input";
		} else {
			Pages pages = new Pages();
			pages.setCurrentPage(page);
			pages.setPageSize(rows);
            if(users.getLevel()!=4)
            {
			result = userManage.pictureList(pages,UtilsTools.convertToChinese(photoName),startDate,endDate, brandId,category,flag);
            }else
            {
            	result = userManage.pictureList(pages,UtilsTools.convertToChinese(photoName),startDate,endDate, users.getId(),category,flag);
            }
		}
		return "success";
	}

	/**
	 * 获得相册列表
	 * 
	 * @return
	 */
	public String picturesList() throws Exception {
		users=userManage.getUser(userId);
		userDetial = userManage.getSingleUser(userId);
			 pages=new Pages();
			pages.setCurrentPage(currentPage);
			pages.setPageSize(6);
			String path = ServletActionContext.getRequest().getRealPath("/uploadFile");
			picturesList = userManage.picturesList(pages, userId, path,"");
			userDetial = userManage.getSingleUser(userId);
			
			 Pages pageCriticism=new Pages();
			 pageCriticism.setCurrentPage(currentPage);
			 pageCriticism.setPageSize(12);
			String ids="";
			for(int i=0;i<picturesList.size();i++)
			{
				
				ids+= ((String[])picturesList.get(i))[8]+",";
			}
			if(!ids.equals(""))
			{
			ids=ids.substring(0,ids.length()-1);
			groupbyCriticismList=groupCriticismManage.newCriticismPhotoList(pageCriticism,ids);
			}
			listDredgeCitys=dicManage.getDredgeCitys();
		return "picturesList";
	}

	/**
	 * 获得相册列表
	 * 
	 * @return
	 */
	public String picturesListForOption() throws Exception {

		Users users = (Users) ServletActionContext.getRequest().getSession()
				.getAttribute("user");
		if (users == null) {
			this.addActionError("你没有登录，请登录！");
			return "input";
		} else {
			result = userManage.picturesList(users.getId());

		}
		
		return "success";
	}

	/**
	 * 删除相册
	 * 
	 * @return
	 */
	public String delPictures() throws Exception {
		String path = ServletActionContext.getRequest().getRealPath(
				"/uploadFile");
		result = userManage.delPictures(picId, path);
		return "success";
	}

	/**
	 * 推荐相册
	 * 
	 * @return
	 */
	public String ratifyPic() throws Exception {

		result = userManage.ratifyPic(picId, able);
		return "success";
	}

	/**
	 * 上传照片
	 * 
	 * @return
	 */
	public String addPhoto() throws Exception {

		Pictures pic = userManage.getPictures(picId);
		
		File[] files = getUpload();

		InputStream is = null;
		OutputStream os = null;
		try {
			for (int i = 0; i < files.length; i++) {
				is = new FileInputStream(upload[i]);
				String path = ServletActionContext.getRequest().getRealPath(
						"\\uploadFile" + "\\" + pic.getImageFolder());
				String image = new Date().getTime()
						+ "."
						+  uploadFileName[i].substring(uploadFileName[i]
								.lastIndexOf(".") + 1, uploadFileName[i]
								.length());
				path=path.replace("/", File.separator).replace("\\",File.separator);
				os = new FileOutputStream(new File(path, image));
				byte[] buffer = new byte[400];
				int length = 0;
				while ((length = is.read(buffer)) > 0) {
					os.write(buffer, 0, length);
				}
				Photoinfor pi=new Photoinfor();
				pi.setPicId(picId);
				pi.setTitle(title[i]);
				pi.setDescription(descriptions[i]);
				pi.setPhotoName(pic.getImageFolder()+"/"+image);
				SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				pi.setDatetime(sdf.format(new Date()));
				if(pic.getFace().equals("img.gif"))
				{
					pic.setFace(pic.getImageFolder()+"/"+image);
					userManage.modifyPicture(pic);
				}
				boolean isSuccess=userManage.addPhoto(pi);
			}
			is.close();
			os.close();
			
		} catch (Exception e) {
			e.printStackTrace();
			this.addActionError("上传失败！");
		}
		this.addActionMessage("上传成功!");
		return "AddPhoto";
	}
	/**
	 * 修改相册
	 * @return
	 * @throws Exception
	 */
	public String modifyPicture() throws Exception {
		Pictures pic = userManage.getPictures(picId);
		pic.setPhotoName(UtilsTools.convertToChinese(photoName));
		pic.setDescription(UtilsTools.convertToChinese(description));
		result=userManage.modifyPicture(pic);
		photoName=null;
		return "success";
	}
/**
 * 显示相册图片
 * @return
 */
	public String showPhotoList() throws Exception {
		users=userManage.getUser(userId);
		userDetial = userManage.getSingleUser(userId);
		pages=new Pages();
		pages.setCurrentPage(currentPage);
		pages.setPageSize(12);
		showPhotoList= userManage.showPhotoList(pages,picId);
		
		Pages pagestemp=new Pages();
		pagestemp.setCurrentPage(currentPage);
		pagestemp.setPageSize(12);
		criticismList=groupCriticismManage.newCriticismPhotoList(pagestemp,picId+"");

		photoName=new String(UtilsTools.convertToChinese(this.photoName));
		listDredgeCitys=dicManage.getDredgeCitys();
		return "showPhotoList";
	}
	/**
	 * 回应图片
	 * @return
	 */
	public String criticismPhoto()throws Exception
	{
		users=userManage.getUser(userId);
		userDetial = userManage.getSingleUser(userId);
		pages=new Pages();
		 pic = userManage.getPictures(picId);
		 photoinfor= userManage.criticismPhoto(pages,photoId,picId);
		 
		 pagesCriticism=new Pages();
		 pagesCriticism.setCurrentPage(currentPages);
		 pagesCriticism.setPageSize(12);
		 criticismList=groupCriticismManage.criticismPhotoList(pagesCriticism,photoinfor.getId());
		 listDredgeCitys=dicManage.getDredgeCitys();
		return "CriticismPhoto";
	}
	/**
	 * 添加图片回应信息
	 * @return
	 */
	public String addCriticismPhoto()throws Exception
	{
		
		Users users = (Users) ServletActionContext.getRequest().getSession()
		.getAttribute("user");
		GroupCriticism  gc=new GroupCriticism();
		gc.setUserId(users.getId());
		 try {
			 content=new String(content.getBytes("ISO-8859-1"),"utf-8");
				
			} catch (UnsupportedEncodingException e) {
				
				e.printStackTrace();
			} 
		gc.setContent(content);
		gc.setGroupbyId(photoId);
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		gc.setDatetime(sdf.format(new Date()));
		gc.setFlag(4);
		gc.setUrl(url);
		groupCriticismManage.addGroupCriticism(gc);
		listDredgeCitys=dicManage.getDredgeCitys();
		return "AddCriticismPhoto";
	}
	/**
	 * 上传图片
	 */
	@SuppressWarnings("deprecation")
	public String uploadImage() throws Exception
	{
		@SuppressWarnings("unused")
		File files = imgFile;
		String path = ServletActionContext.getRequest().getRealPath("/uploadFile/" );
		String image = new Date().getTime()+ "."+ imgFileFileName.substring(imgFileFileName.lastIndexOf(".") + 1, imgFileFileName.length());
		InputStream is = null;
		OutputStream os = null;
		result = new JSONObject();
		try {
			
				is = new FileInputStream(files);
				
				
				os = new FileOutputStream(new File(path, image));
				byte[] buffer = new byte[400];
				int length = 0;
				while ((length = is.read(buffer)) > 0) {
					os.write(buffer, 0, length);
				}
			
			is.close();
			os.close();
			result.put("error", 0);
		} catch (Exception e) {
			e.printStackTrace();
			result.put("error", 1);
		}
		 
		 
		 result.put("url", "../../uploadFile/"+ image);
		return "success";
	}
	/**
	 * 添加品牌
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public String addBrandInfor()throws Exception
	{
		
		Users users = (Users) ServletActionContext.getRequest().getSession().getAttribute("user");
		BrandInfor brandInfor=new BrandInfor();
		brandInfor.setTitle(brandName);
		brandInfor.setUserId(users.getId().toString());
		brandInfor.setCategory(category);
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		brandInfor.setDatetime(sdf.format(new Date()));
		brandInfor.setContent(description);
		brandInfor.setRecommendation(0);
		brandInfor.setCategory2(category2);
		@SuppressWarnings("unused")
		List imageUrl=UtilsTools.getImgStr(description);
		if(imageUrl!=null&&imageUrl.size()!=0)
		{
			String image=imageUrl.get(0).toString();
			brandInfor.setImage1(image.substring(image.lastIndexOf("/")+1,image.length()));
		}else
		{
			brandInfor.setImage1("img.gif");
		}
	  result=userManage.addBrandInfor(brandInfor);
		return "AddBrandInfor";
	}
	
	/**
	 * 获得所有品牌列表
	 * @return
	 */
	public String brandInforAllList()throws Exception
	{
		users=userManage.getUser(userId);
		userDetial = userManage.getSingleUser(userId);
		pages=new Pages();
		pages.setCurrentPage(currentPage);
		pages.setPageSize(6);
		 brandInforList=userManage.brandInforAllList(pages,userId);
		 Pages pagetemp=new Pages();
		 pagetemp.setCurrentPage(1);
		 pagetemp.setPageSize(100);
		 List temp=userManage.brandInforAllList(pagetemp,userId);
		 if(temp!=null&&temp.size()!=0)
		 {
		 String brandId="";
		 for(int i=0;i<temp.size();i++)
		 {
			 BrandInfor bi=(BrandInfor)((Object[])temp.get(i))[0];
			 
			 brandId+= bi.getId()+","; 
		 }
		 brandId=brandId.substring(0,brandId.length()-1);
		 
		 pagetemp.setCurrentPage(1);
		 pagetemp.setPageSize(12);
		 criticismList=groupCriticismManage.brandNewCriticismList(pagetemp,brandId);
		 }
		 listDredgeCitys=dicManage.getDredgeCitys();
		return "BrandInforAllList";
	}
	/**
	 * 管理所有品牌列表
	 */
	public String manageBrandInforAllList()throws Exception
	{
		Users users = (Users) ServletActionContext.getRequest().getSession().getAttribute("user");
		pages=new Pages();
		pages.setCurrentPage(Integer.parseInt(ServletActionContext.getRequest().getParameter("page")));
		pages.setPageSize(Integer.parseInt(ServletActionContext.getRequest().getParameter("rows")));
		String title=ServletActionContext.getRequest().getParameter("title");
		String startDate=ServletActionContext.getRequest().getParameter("startdate");
		String endDate=ServletActionContext.getRequest().getParameter("enddate");
		 if(users.getLevel()==1||users.getLevel()==5||users.getLevel()==6||users.getLevel()==7||users.getLevel()==8)
		 {
			 result=userManage.manageBrandInforAllList(pages,brandId,title,startDate,endDate,category,flag);
		 }else
		 {
			 result=userManage.manageBrandInforAllList(pages,users.getId(),title,startDate,endDate,category,flag);
		 }
		 
		
		return "success";
	}
	/**
	 * 获得单个类别的列表
	 * @return
	 */
	public String brandSingleCategoryList()throws Exception
	{
		
		pages=new Pages();
		pages.setCurrentPage(currentPage);
		pages.setPageSize(20);
		 brandInforList=userManage.brandSingleCategoryList(pages,userId,category);
		 singleCategory=groupbyManage.findCategoryById(category);
		 String brandId="";
		 for(int i=0;i<brandInforList.size();i++)
		 {
			 BrandInfor bi=(BrandInfor)(brandInforList.get(i));
			 
			 brandId+= bi.getId()+",";
		 }
		 brandId=brandId.substring(0,brandId.length()-1);
		 Pages pagetemp=new Pages();
		 pagetemp.setCurrentPage(currentPage);
		 pagetemp.setPageSize(12);
		 criticismList=groupCriticismManage.brandNewCriticismList(pagetemp,brandId);
		 listDredgeCitys=dicManage.getDredgeCitys();
		return "BrandSingleCategoryList";
	}
	/**
	 * 单个品牌信息展示
	 * @return
	 */
	public String singleBrand()throws Exception
	{
		users=userManage.getUser(userId);
		userDetial = userManage.getSingleUser(userId);
		pages=new Pages();
		pages.setCurrentPage(currentPage);
		pages.setPageSize(20);
		singleBrand=userManage.singleBrand(brandId);
		 singleCategory=groupbyManage.findCategoryById(category);
		 criticismList=groupCriticismManage.criticismBrandList(pages,brandId,5);
		 listDredgeCitys=dicManage.getDredgeCitys();
		return "SingleBrand";
	}
	/**
	 * 获得单个资讯信息
	 * @return
	 */
	public String singleBrandInfor()throws Exception
	{
		
		singleBrand=userManage.singleBrand(brandId);
		 
		return "SingleBrandInfor";
	}
	/**
	 * 添加品牌评论信息
	 * @return
	 */
	public String addBrandCriticism()throws Exception
	{
		Users users = (Users) ServletActionContext.getRequest().getSession()
		.getAttribute("user");
		GroupCriticism  gc=new GroupCriticism();
		gc.setUserId(users.getId());
		
		gc.setContent(content);
		gc.setGroupbyId(brandId);
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		gc.setDatetime(sdf.format(new Date()));
		gc.setFlag(5);
		gc.setUrl(url);
		groupCriticismManage.addGroupCriticism(gc);
		return "AddBrandCriticism";
	}
	/**
	 * 添加话题
	 * @return
	 */
	public String addTopic()throws Exception
	{
		Users users = (Users) ServletActionContext.getRequest().getSession()
		.getAttribute("user");
       Topic  topic=new Topic();
       topic.setUserId(publisher);
			 topic.setTitle(UtilsTools.convertToChinese(title[0]));
			 content=new String(content);
		topic.setContent(UtilsTools.convertToChinese(content));
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		topic.setDatetime(sdf.format(new Date()));
		topic.setReplyCount(0);
		topic.setReplyLastTime(sdf.format(new Date()));
		topic.setPublisher(users.getId());
		boolean isSuccess=userManage.addTopic(topic);
		title=null;
		result=new JSONObject();
		result.put("success",true);
		return "success";
	}
	/**
	 * 获得话题列表
	 * @return
	 */
	public String topicList()throws Exception
	{
		users=userManage.getUser(userId);
		userDetial = userManage.getSingleUser(userId);
        pages=new Pages();
        pages.setCurrentPage(currentPage);
        pages.setPageSize(12);
		topicList=userManage.topicList(pages,userId);
		Pages pagesTemp=new Pages();
		pagesTemp.setCurrentPage(currentPage);
		pagesTemp.setPageSize(12);
		String topicId="";
		if(topicList.size()!=0)
		{
		 for(int i=0;i<topicList.size();i++)
		 {
			 Topic bi=(Topic)(((Object[])topicList.get(i))[0]);
			 
			 topicId+= bi.getId()+",";
		 }
		 topicId=topicId.substring(0,topicId.length()-1);
		 
		criticismList=groupCriticismManage.criticismTopicList(pagesTemp,topicId,6);
		}
		listDredgeCitys=dicManage.getDredgeCitys();
		
		return "TopicList";
	}
	/**
	 * 话题管理
	 * @return
	 * @throws Exception
	 */
	public String topicListForJson() throws Exception
	{
		Users users = (Users) ServletActionContext.getRequest().getSession().getAttribute("user");
		Pages pages = new Pages();
		pages.setCurrentPage(page);
		pages.setPageSize(rows);
		if(users.getLevel()==4)
		{
			
		    result = userManage.topicListForJson(pages,users.getId(), title[0], startDate, endDate);
		}else
		{
			result = userManage.topicListForJson(pages,brandId, title[0], startDate, endDate);
		}
		return "success";
	}
	
	/**
	 * 修改话题
	 */
	public String modifyTopic()throws Exception
	{
		Topic topicInfor=userManage.getTopic(topicId);
		topicInfor.setTitle(UtilsTools.convertToChinese(title[0]));
		topicInfor.setContent(UtilsTools.convertToChinese(content));
		result=userManage.modifyTopic(topicInfor);
		return "success";
	}
	/**
	 * 删除话题
	 */
	public String delTopic()throws Exception
	{
		
		result=userManage.delTopic(topicId);
		return "success";
	}
	/**
	 * 删除所有话题
	 */
	public String delAllTopicForUser()throws Exception
	{
		@SuppressWarnings("unused")
		Users users=null;
		if(brandId==-1)
		{
			users= (Users) ServletActionContext.getRequest().getSession().getAttribute("user");
			brandId=users.getId();
		}
		result=userManage.delAllTopicForUser(brandId);
		return "success";
	}
	/**
	 * 显示单个话题评论
	 * @return
	 */
	public String singleTopic()throws Exception
	{
		topic=userManage.getTopic(topicId);
		userDetial= userManage.getSingleUser(userId);
		publishers= userManage.getSingleUser(topic.getPublisher());
		pages=new Pages();
        pages.setCurrentPage(currentPage);
        pages.setPageSize(12);
		 criticismList=groupCriticismManage.criticismBrandList(pages,topicId,6);
		 Pages pagesTemp=new Pages();
		 pagesTemp.setCurrentPage(currentPage);
		 pagesTemp.setPageSize(12);
		 otherTopicList=userManage.topicList(pagesTemp,userId,topicId);
		 listDredgeCitys=dicManage.getDredgeCitys();
		return "SingleTopic";
	}
	/**
	 * 评论话题信息
	 * @return
	 */
	public String addTopicReplay()throws Exception
	{
		Users users = (Users) ServletActionContext.getRequest().getSession().getAttribute("user");
		GroupCriticism  gc=new GroupCriticism();
		gc.setUserId(users.getId());
		 
		gc.setContent(content);
		gc.setGroupbyId(topicId);
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		gc.setDatetime(sdf.format(new Date()));
		gc.setFlag(6);
		gc.setUrl(url);
		groupCriticismManage.addGroupCriticism(gc);
		userManage.updateTopicCount(topicId);
		return "AddTopicReplay";
	}
	/**
	 * 删除品牌
	 * @return
	 */
	@SuppressWarnings("deprecation")
	public String delBrand()throws Exception
	{
		String path=ServletActionContext.getRequest().getRealPath("/uploadFile");
		result=userManage.delBrand(brandId,path);
		return "success";
	}
	/**
	 * 获得单个品牌
	 * @return
	 */
	public String getBrand() {
		result=userManage.getBrand(brandId);
		return "success";
	}
    /**
     * 删除品牌图片
     * @param photoName
     */
	public String delImage()
	{
		String path=ServletActionContext.getRequest().getRealPath("/uploadFile");
		result=userManage.delImage(brandId,flag,uploadFileName[0],path);
		return "success";
	}
	/**
	 * 上传单个品牌图片
	 * @param photoName
	 */
	@SuppressWarnings("unused")
	public String uploadSingleImage()
	{
		File[] files = getUpload();
		String image=null;
		try {
			InputStream is = new FileInputStream(files[0]);
			
			 image = new Date().getTime()+ "."+ uploadFileName[0].substring(uploadFileName[0].lastIndexOf(".") + 1, uploadFileName[0].length());
			String path = ServletActionContext.getRequest().getRealPath("/uploadFile");
			OutputStream os = new FileOutputStream(new File(path, image));
			byte[] buffer = new byte[400];
			int length = 0;
			while ((length = is.read(buffer)) > 0) {
				os.write(buffer, 0, length);
			}
			is.close();
			os.close();
			
		} catch (Exception e) {
			e.printStackTrace();
			this.addActionError("上传失败！");
		}
		result=userManage.uploadSingleImage(brandId,flag,image);
		return "UploadSingleImage";
	}
	/**
	 * 获得品牌用户信息列表
	 */
	@SuppressWarnings("unchecked")
	public String brandUserListMore()
	{
		Pages page=new Pages();
		page.setCurrentPage(1);
		page.setPageSize(10);
	  List	brandUserListMore=dicManage.getCategoryForList(3);
	  brandUserList=new ArrayList();
		  for(int i=0;i<brandUserListMore.size();i++)
		  {
			  Object[] temp=new Object[3];
			  Category category=(Category)brandUserListMore.get(i);
			  temp[0]=category.getId().toString();
			  temp[1]=category.getCategoryName();
			  
			  List list=userManage.brandUserListByCategory(page,category.getId());
			  temp[2]=list; 
			  if(list.size()!=0)
			  {
				  brandUserList.add(temp);
			  }
		  }
		  page.setCurrentPage(1);
			page.setPageSize(7);
		  groupbyCriticismList = groupCriticismManage.getGroupbyUserCriticismList(-1, page);
		  listDredgeCitys=dicManage.getDredgeCitys();
		return "BrandUserListMore";
	}
	/**
	 * 获得单个类别的品牌用户
	 */
	@SuppressWarnings("unchecked")
	public String brandUserByCategory()
	{
		 pages=new Pages();
		pages.setCurrentPage(1);
		pages.setPageSize(50);
	     brandUserList=userManage.brandUserListByCategory(pages,category);
	     Pages page=new Pages();
	     page.setCurrentPage(1);
	     page.setPageSize(12);
	     String userId="";
		 for(int i=0;i<brandUserList.size();i++)
		 {
			 UserDetial bi=(UserDetial)(brandUserList.get(i));
			 
			 userId+= bi.getUserId()+",";
		 }
		 userId=userId.substring(0,userId.length()-1);
		 Pages pagetemp=new Pages();
		 pagetemp.setCurrentPage(currentPage);
		 pagetemp.setPageSize(12);
		 criticismList=groupCriticismManage.brandNewCriticismList(pagetemp,userId);
		 
		  singleCategory=groupbyManage.findCategoryById(category);
		  listDredgeCitys=dicManage.getDredgeCitys();
		return "BrandUserByCategory";
	}
	/**
	 * 图片展示
	 */
	public String photoList()
	{
		pages=new Pages();
		pages.setCurrentPage(currentPage);
		pages.setPageSize(6);
		showPhotoList= userManage.showPhotoList(pages,picId);
		
		return "PhotoList";
	}
	/**
	 * 修改相册图片
	 */
	public String photoModify()
	{
		Pages page=new Pages();
		page.setCurrentPage(1);
		page.setPageSize(1);
		Photoinfor photoinfor= userManage.criticismPhoto(page,photoId,-1);
		if(this.getTitle()[0]!=null)
		{
		    	try {
					String title=new String(this.getTitle()[0].getBytes("ISO-8859-1"),"utf-8");
					photoinfor.setTitle(title);
				} catch (Exception e) {
					
					e.printStackTrace();
				} 
		}
		if(this.getDescription()!=null)
		{
		  
		   try {
			   String description=new String(this.getDescription().getBytes("ISO-8859-1"),"utf-8");
				 photoinfor.setDescription(description);
			} catch (Exception e) {
				e.printStackTrace();
			} 
		}
		result=userManage.photoModify(photoinfor);
		return "success";
	}
	/**
	 * 删除相册里的图片
	 */
	public String photoDel()
	{
		String path=ServletActionContext.getRequest().getRealPath("/uploadFile");
		result=userManage.photoDel(photoId,path);
		return "success";
	}
	/**
	 * 设图片为相册封面
	 */
	public String pictureFace()
	{
		String image=uploadFileName[0];
		result=userManage.pictureFace(picId,image);
		return "success";
	}
	/**
	 * 更新brand信息
	 * @param photoName
	 */
	public String modifyBrand()
	{
		result=userManage.modifyBrand(brandId,UtilsTools.convertToChinese(title[0]),UtilsTools.convertToChinese(content),category,category2);
		return "success";
	}
	
	/**
	 * 推荐brand信息
	 * @param photoName
	 */
	public String recommendation()
	{
		result=userManage.modifyBrand(brandId,flag);
		return "success";
	}
	
	public void setPhotoName(String photoName) {
		this.photoName = photoName;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public UsersManage getUserManage() {
		return userManage;
	}

	public void setUserManage(UsersManage userManage) {
		this.userManage = userManage;
	}

	public JSONObject getResult() {
		return result;
	}

	public Pages getPages() {
		return pages;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getRows() {
		return rows;
	}

	public void setRows(int rows) {
		this.rows = rows;
	}

	public int getPicId() {
		return picId;
	}

	public void setPicId(int picId) {
		this.picId = picId;
	}

	public int getAble() {
		return able;
	}

	public void setAble(int able) {
		this.able = able;
	}

	public List getPicturesList() {
		return picturesList;
	}

	public List getGroupbyCriticismList() {
		return groupbyCriticismList;
	}

	public GroupCriticismManage getGroupCriticismManage() {
		return groupCriticismManage;
	}

	public void setGroupCriticismManage(
			GroupCriticismManage groupCriticismManage) {
		this.groupCriticismManage = groupCriticismManage;
	}

	public UserDetial getUserDetial() {
		return userDetial;
	}

	public String getFlag() {
		return flag;
	}

	public void setFlag(String flag) {
		this.flag = flag;
	}

	public File[] getUpload() {
		return upload;
	}

	public void setUpload(File[] upload) {
		this.upload = upload;
	}

	public String[] getUploadContentType() {
		return uploadContentType;
	}

	public void setUploadContentType(String[] uploadContentType) {
		this.uploadContentType = uploadContentType;
	}

	public String[] getUploadFileName() {
		return uploadFileName;
	}

	public void setUploadFileName(String[] uploadFileName) {
		this.uploadFileName = uploadFileName;
	}

	public String[] getTitle() {
		return title;
	}

	public void setTitle(String[] title) {
		
		this.title = title;
	}

	public String[] getDescriptions() {
		return descriptions;
	}

	public void setDescriptions(String[] descriptions) {
		this.descriptions = descriptions;
	}

	public List getShowPhotoList() {
		return showPhotoList;
	}

	public int getPhotoId() {
		return photoId;
	}

	public void setPhotoId(int photoId) {
		this.photoId = photoId;
	}

	public Photoinfor getPhotoinfor() {
		return photoinfor;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	

	public Pages getPagesCriticism() {
		return pagesCriticism;
	}

	public int getCurrentPages() {
		return currentPages;
	}

	public void setCurrentPages(int currentPages) {
		this.currentPages = currentPages;
	}

	public String getBrandName() {
		return brandName;
	}

	public void setBrandName(String brandName) {
		this.brandName = brandName;
	}

	public int getCategory() {
		return category;
	}

	public void setCategory(int category) {
		this.category = category;
	}

	public List getBrandInforList() {
		return brandInforList;
	}

	public int getUserId() {
		return userId;
	}

	public void setUserId(int userId) {
		this.userId = userId;
	}

	public GroupbyManage getGroupbyManage() {
		return groupbyManage;
	}

	public void setGroupbyManage(GroupbyManage groupbyManage) {
		this.groupbyManage = groupbyManage;
	}

	public Category getSingleCategory() {
		return singleCategory;
	}

	public int getBrandId() {
		return brandId;
	}

	public void setBrandId(int brandId) {
		this.brandId = brandId;
	}

	public BrandInfor getSingleBrand() {
		return singleBrand;
	}

	public List getCriticismList() {
		return criticismList;
	}

	public List getTopicList() {
		return topicList;
	}

	public int getTopicId() {
		return topicId;
	}

	public void setTopicId(int topicId) {
		this.topicId = topicId;
	}

	public Topic getTopic() {
		return topic;
	}

	public List getOtherTopicList() {
		return otherTopicList;
	}

	public void setOtherTopicList(List otherTopicList) {
		this.otherTopicList = otherTopicList;
	}

	public DicManage getDicManage() {
		return dicManage;
	}

	public void setDicManage(DicManage dicManage) {
		this.dicManage = dicManage;
	}

	public List getBrandUserList() {
		return brandUserList;
	}

	public String getPhotoName() {
		return photoName;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	public List getListDredgeCitys() {
		return listDredgeCitys;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public String getStartDate() {
		return startDate;
	}

	public void setStartDate(String startDate) {
		this.startDate = startDate;
	}

	public String getEndDate() {
		return endDate;
	}

	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}

	public int getCategory2() {
		return category2;
	}

	public void setCategory2(int category2) {
		this.category2 = category2;
	}

	public Users getUsers() {
		return users;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public int getPublisher() {
		return publisher;
	}

	public void setPublisher(int publisher) {
		this.publisher = publisher;
	}

	public File getImgFile() {
		return imgFile;
	}

	public void setImgFile(File imgFile) {
		this.imgFile = imgFile;
	}

	public String getImgFileContentType() {
		return imgFileContentType;
	}

	public void setImgFileContentType(String imgFileContentType) {
		this.imgFileContentType = imgFileContentType;
	}

	public String getImgFileFileName() {
		return imgFileFileName;
	}

	public void setImgFileFileName(String imgFileFileName) {
		this.imgFileFileName = imgFileFileName;
	}

	public Pictures getPic() {
		return pic;
	}

	public UserDetial getPublishers() {
		return publishers;
	}

}
